//
// Created by wujehy on 2020/8/4.
//

#ifndef AUTH_RAFT_AUTHMOD_H
#define AUTH_RAFT_AUTHMOD_H

#include <map>
#include <cstdint>
#include "BusinessBase.h"

class NetWorkWarpper;

class BusinessManager;

class UserDB;

class AuthMod : public BusinessBase<NetWorkWarpper>
{
    enum AUTH_MOD_TYPE
    {
        AUTH_REGISTER = 1,
        AUTH_LOGIN = 2,
        AUTH_LOGOUT = 3,
        AUTH_CHANGE_PASSWORD = 5,
    };
    std::map<int, BusinessBaseEventFunction> m_type_event_map;
    BusinessBaseEventFunction register_event_function;
    BusinessBaseEventFunction login_event_function;
    BusinessBaseEventFunction logOut_event_function;
    BusinessBaseEventFunction changePassword_event_function;


protected:
//    void Register(int64_t tcpid, void *data, int len);
//    void Login(int64_t tcpid, void *data, int len);
//    void LogOut(int64_t tcpid, void *data, int len);
//    void ChangePassword(int64_t tcpid, void *data, int len);
    void init_callback_function();

    int init_event();

    BusinessManager *businessManager = nullptr;

    // 惰性加载
    UserDB *userTable = nullptr;
public:
    AuthMod();

    int type() override;

    int depackage(int taskid, int type, void *data, int len, void *userdata = nullptr) override;

    void setBusinessManager(BusinessManager *businessManager);

    void init_finished() override;

};


#endif //AUTH_RAFT_AUTHMOD_H
